import {login} from '../../api/user'
// pages/login/index.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    username:"",
    password:"",
    loading:false
  },
  login(){
    this.setData({
      loading:true
    })
    login(this.data.username,this.data.password).then(res=>{
      this.setData({
        loading:false
      })
      if(res.data.code === 0 ){
        const cookie = res.cookies.join(";");
        if(cookie.includes("JSESSIONID")){
          // 需要把cookie
          wx.setStorageSync('cookie', cookie)
        }
        // 轻提示
        wx.showToast({
          title: '登录成功',
        })
        getApp().checkLoginStatus()

        wx.switchTab({
          url: '/pages/mine/mine',
        })
      }else {
        // 展示模态框
        wx.showModal({
          title:"登录失败",
          content:res.data.msg,
          confirmText:"我知道了",
          showCancel:false
        })
      }
    })
  },
})